home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d2 / stayres.arc / STAYRSTR.340 < prev    next >
Text File  |  1988-06-27  |  7KB  |  116 lines

  1. {****************************************************************************}
  2. {                  S  T  A  Y  R  S  T  R  .  I  N  C                        }
  3. {                                                                            }
  4. {           This is the StayRstr.Inc file included above                     }
  5. {       Separate the code out into a file or replace the $I StayRstr.331     }
  6. {                  statement above with this code.                           }
  7. {****************************************************************************}
  8. {Version 3.31}
  9.                { Inline Code to restore the stack and regs moved}
  10.                { to the Turbo Resident Stack which allows       }
  11.                { re-entrancy into Dos for I/O and  recursion    }
  12.                { for Turbo Terminate & Stay Resident programs.  }
  13.  
  14.        { Author: Lane Ferris                                       }
  15.        {         - The Hunter's Helper -                           }
  16.        { Distributed to the Public Domain for use without profit.  }
  17.        { Original Version 5.15.85                                  }
  18. {----------------------------------------------------------------------}
  19. {        Restore the Dos (or interrupted pgm) Regs and Stack           }
  20. {----------------------------------------------------------------------}
  21.            { On entry the Stack will already contain: }
  22.            {    Pointer to bottom of stack            }
  23.            {    Bottom of Dos Stack Ptr               }
  24.            {    StackSize words of saved pgm stack    }
  25.            {    Dos Flags                             }
  26.            {    Dos Code Segment                      }
  27.            {    Dos Instruction Ptr                   }
  28.            {    Dos Base Pointer                      }
  29.            {    Dos Original Stack Ptr                }
  30.  
  31.  
  32.            { Retrieve the Regpack registers as they were    }
  33.            { stored for the Interrupt Entry.                }
  34.  
  35.     inline(
  36.     $BD/Regs/                          {Mov    Bp,offset REGS}
  37.     $2E/$8B/$46/$00/                   {CS:Mov Ax,[Bp+0]}
  38.     $2E/$8B/$5E/$02/                   {Cs:Mov Bx,[Bp+2]}
  39.     $2E/$8B/$4E/$04/                   {CS:Mov Cx,[Bp+4]}
  40.     $2E/$8B/$56/$06/                   {CS:Mov Dx,[Bp+6]}
  41.  
  42.     $2E/$8B/$76/$0A/                   {CS:Mov Si,[Bp+A]}
  43.     $2E/$8B/$7E/$0C/                   {CS:Mov Di,[Bp+C]}
  44.     $2E/$8E/$5E/$0E/                   {CS:Mov DS,[Bp+E]}
  45.     $2E/$8E/$46/$10/                   {CS:Mov ES,[Bp+10]}
  46.     $2E/$FF/$76/$12/                   {Push Cs:[Bp+12]  }
  47.                                        {PopF             }
  48.             { The following code was added to avoid }
  49.             { the 80286 Pop flag (POPF) bug which   }
  50.             { enables interrupts while we are trying}
  51.             { to POP  the stack on odd byte boundry }
  52.     $EB/$01/                           {JMP $+3 Skip over IRET   }
  53.     $CF/                               {IRET    POP IP/CS/Flags  }
  54.     $0E/                               {PUSH CS Make a return    }
  55.     $E8/$FB/$FF/                       {CALL CS:$-2 Pop the Flags}
  56.  
  57.            { If [Cs:InUse]:= True,  then dont restore the stack.}
  58.            { This program is being recursive. Else restore  Dos }
  59.            { Stack and Program Entry registers for final exit.  }
  60.  
  61.      $2E/$80/$3E/Inuse/$01/   {Cmp  byte ptr Cs:[Inuse],1                   }
  62.      $74/$25/                 {Je   ReCurOut   J-U-M-P                      }
  63.  
  64.            { Move "StackSize" words back to the interrupted pgms}
  65.            { stack. The originals could have been clobber by our}
  66.            { being recursive. (Especially true of DOS)          }
  67.  
  68.     $FA /                    { Cli      ; Stop all interrupts    }
  69.     $5E/                     {Pop Si     Bottom of Dos Stack              }
  70.     $2E/$8B/$0E/StackSize/   {Mov Cx,Cs:StackSize Saved Stack Words       }
  71.     $2E/$8E/$06/DosSSeg/     {Mov ES,Cs:DosSSeg Get Dos StackSegment      }
  72.   {Restack:}
  73.     $4E/$4E/                 {Dec Si/Dec Si     Backup Dos Stack          }
  74.     $26/$8F/$04/             {Pop Es:[Si]       Dos Stack := Our Stack    }
  75.     $E2/$F9/                 {Loop to Restack                             }
  76.     $89/$F5/                 {Mov Bp,Si         Save Dos Sp across Pops   }
  77.  
  78.            {         - C - A - U - T - I - O - N -              }
  79.            { Restore the original interrupted programs regs     }
  80.            { except Ax. Ax usually contains status. It contains }
  81.            { a scan code and key for Int 16. You may want to    }
  82.            { rework this if using another interrupt.            }
  83.  
  84.     $07/                     {Pop  Es                                     }
  85.     $1F/                     {Pop  Ds                                     }
  86.     $5F/                     {Pop  Di                                     }
  87.     $5E/                     {Pop  Si                                     }
  88.     $5A/                     {Pop  Dx                                     }
  89.     $59/                     {Pop  Cx                                     }
  90.     $5B/                     {Pop  Bx                                     }
  91.     $44/$44/                 {Inc sp/Inc sp Thow old Ax value away        }
  92.  
  93.     $89/$EC/                  {Mov  Sp,Bp         Setup Dos Stack Ptr     }
  94.     $2E/$8E/$16/DosSSeg/      {Mov  SS,Cs:DosSSeg Give back Dos Stack     }
  95.  
  96. {RecurOut}                             {Clean up the Stack                }
  97.     $5D/                               {Pop Bp     Throw away old dos Sp  }
  98.     $BD/Regs/                          {Mov Bp,offset REGS                }
  99.     $2E/$FF/$76/$12/                   {Push Cs:[Bp+12]  Flags from last  }
  100.                                        {PopF             interrupt.       }
  101.             { The following code was added to avoid  }
  102.             { the 80286 Pop flag (POPF) bug which    }
  103.             { enables interrupts while we are trying }
  104.             { to POP  the stack on odd byte boundry  }
  105.  
  106.     $EB/$01/                           {JMP $+3 Skip over IRET   }
  107.     $CF/                               {IRET    POP IP/CS/Flags  }
  108.     $0E/                               {PUSH CS Make a return    }
  109.     $E8/$FB/$FF/                       {CALL CS:$-2 Pop the Flags}
  110.  
  111.     $5D/                               {Pop Bp  Retrieve old BP        }
  112.     $FB/                               {Sti     Enable interrupts      }
  113.     $CA/$02/$00                        {Ret Far 002 Thow old flags away}
  114.         );
  115. {.......................................................................}
  116.